<template>
  <main class="page">
    <slot name="top" />
    <div class="wrap">
      <Content class="theme-default-content" />
      <div ref="simulator" class="simulator-box" v-if="getH5Url() !==''">
        <div class="simulator-top">
          <div class="simulator-top_box"></div>
        </div>
        <div class="simulator-content">
          <!-- <div class="simulator-seat"></div> -->
          <iframe class="simulator-iframe" :src="getH5Url()"></iframe>
        </div>
        <div class="simulator-bottom">
          <div class="simulator-bottom_box"></div>
        </div>
      </div>
    </div>
    <PageEdit />

    <PageNav class="page-nav" v-bind="{ sidebarItems }" />

    <slot name="bottom" />
  </main>
</template>

<script>
import PageEdit from '@theme/components/PageEdit.vue';
import PageNav from '@theme/components/PageNav.vue';
import config from '../../config';
export default {
  components: { PageEdit, PageNav },
  props: ['sidebarItems', 'item'],
  data() {
    return {
      h5Host: 'https://h5.ggui.cn/#/pages/'
    };
  },
  created() {
    this.h5Url = this.getH5Url();
    //友盟代码统计
    // let script = document.createElement('script');
    // script.src = 'https://s4.cnzz.com/z_stat.php?id=1279265777&web_id=1279265777';
    // script.language = 'JavaScript';
    // document.body.appendChild(script);
  },
  mounted() {
    //友盟代码统计
    // const script = document.createElement('script')
    // script.src = 'https://s4.cnzz.com/z_stat.php?id=1279265777&web_id=1279265777';
    // script.language = 'JavaScript';
    // document.body.appendChild(script);
  },
  methods: {
    getH5Url() {
      let group = /\/[\s\S]*?\//.exec(this.$route.path)[0]
      if (group && config.themeConfig.sidebar[group]) {
        let sidebarItem = [...config.themeConfig.sidebar[group]]
        for (const key in sidebarItem) {
          for (const k in sidebarItem[key].children) {
            if (group + sidebarItem[key].children[k].path + '.html' == this.$route.path && sidebarItem[key].children[k].h5Url) {
              return this.h5Host + sidebarItem[key].children[k].h5Url
            }
          }
        }

      }
      return '';
    }
  },
  mounted() { }
};
</script>

<style lang="stylus">
@require '../styles/wrapper.styl';

.uni-scroll-view::-webkit-scrollbar {
  width: 4px;
  /* height: 4px; */
}

.uni-scroll-view::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  background: rgba(0, 0, 0, 0.2);
}

.uni-scroll-view::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  border-radius: 0;
  background: rgba(0, 0, 0, 0.1);
}

.page {
  padding-bottom: 2rem;
  display: block;
}

.wrap {
  max-width: 1400px;
  display: flex;
  width: auto;
  margin: 0 auto;

  .simulator-box {
    position: -webkit-sticky;
    position: sticky;
    z-index: 9;
    display: flex;
    flex-direction: column;
    margin-left: 0px;
    flex-shrink: 0;
    width: 414px;
    height: 860px;
    border-radius: 20px;
    background-color: #333;
    box-shadow: 0px 0px 10px 2px rgba(0, 0, 0, 0.2);
    transform: scale(0.8);
    top: 10px;

    .simulator-top {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-shrink: 0;
      height: 36px;

      // border 1px red solid
      .simulator-top_box {
        width: 55px;
        height: 14px;
        background-color: #222;
        border-radius: 8px;
        box-shadow: -1px -2px 1px 0px rgba(255, 255, 255, 0.4) inset;
      }
    }

    .simulator-content {
      position: relative;
      height: 100%;
      margin: 0 20px;
      border-radius: 5px;
      background-color: #FFFFFF;
    }

    .simulator-seat {
      position: absolute;
      left: 0px;
      top: 0px;
      width: 44px;
      height: 44px;
      background-color: rgb(0, 122, 255);
    }

    .simulator-iframe {
      width: 100%;
      height: 100%;
      border: none;
      height: 750px;
    }

    .simulator-bottom {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-shrink: 0;
      height: 70px;

      .simulator-bottom_box {
        position: relative;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background-color: #555;
        border: 1px #666 solid;
        box-shadow: 0px 10px 5px 1px rgba(0, 0, 0, 0.3) inset;

        &::after {
          content: '';
          position: absolute;
          width: 15px;
          height: 15px;
          margin: auto;
          top: 1px;
          left: 0;
          bottom: 0;
          right: 0;
          border-radius: 5px;
          border: 2px #777 solid;
        }
      }
    }

    &.simulator-fixed {
      position: fixed;
    }

    @media (max-width: 1300px) {
      display: none;
    }
  }
}

.page-nav {
  max-width: 1400px;
  margin: 0 auto;

  .inner {
    display: flex;
    justify-content: space-between;
  }
}
</style>
